home *** CD-ROM | disk | FTP | other *** search
- unit TrimWorkingSet;
-
- interface
-
- implementation
-
- uses
- SysUtils, Windows, ExtCtrls;
-
- type
- TTrimmer = class(TTimer)
- public
- procedure TimerTick(Sender: TObject);
- end;
-
- procedure TTrimmer.TimerTick(Sender: TObject);
- var
- CurrentPID, FocusedPID: THandle;
- begin
- CurrentPID := GetCurrentProcessId;
- GetWindowThreadProcessId(GetForegroundWindow, @FocusedPID);
- if (Win32Platform = VER_PLATFORM_WIN32_NT) and //running on NT
- (CurrentPID <> FocusedPID) then //app not foreground process
- SetProcessWorkingSetSize(CurrentPID, Cardinal(-1), Cardinal(-1) );
- end;
-
- var
- Timer: TTrimmer;
-
- initialization
- Timer := TTrimmer.Create(nil);
- Timer.Interval := 30000;
- Timer.OnTimer := Timer.TimerTick;
- finalization
- if Assigned(Timer) then
- Timer.Free;
- end.
-